﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WMPLib;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;

namespace demo07
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void parseLink(string link)
        {
            WebRequest rq = WebRequest.Create(link);
            WebResponse rp = rq.GetResponse();
            StreamReader stream = new StreamReader(rp.GetResponseStream());

            string htmlContent = stream.ReadToEnd();

            Match m = Regex.Match(htmlContent, "xmlURL=([^&]*)&");
            string linkxml = m.Groups[1].Value;

            rq = WebRequest.Create(linkxml);
            rp = rq.GetResponse();
            stream = new StreamReader(rp.GetResponseStream());
            string xml = stream.ReadToEnd();

            m = Regex.Match(xml, "title><[^>]*>");
            listBox1.Items.Clear();
            string tmp;
            while (m.Groups[0].Value != "")
            {
                tmp = m.Groups[0].Value;
                string title = tmp.Substring(16, m.Length - 20);
               listBox1.Items.Add(title);
                m = m.NextMatch();
            }

            m = Regex.Match(xml, "source><[^>]*>");
            Url.Text = "";
            while (m.Groups[0].Value != "")
            {
                tmp = m.Groups[0].Value;
                Url.Text = tmp.Substring(16,tmp.Length-19);
                m = m.NextMatch();
            }
            axWindowsMediaPlayer1.URL = Url.Text;
            axWindowsMediaPlayer1.Ctlcontrols.play();
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            parseLink(textBox1.Text);
        }
    }
}
